<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page language="java" import="com.soft.model.*"%>
<%@ page language="java" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="ckfinder/ckfinder.js"></script>
<script type="text/javascript">
	var editor = null;
	window.onload = function() {
		//参数'content'是textarea元素的name属性值，而非id属性值
		editor = CKEDITOR.replace("villaDescription");
		CKFinder.setupCKEditor(editor, 'ckfinder/');
	}
	
	function changeImg(e){  
        for (var i = 0; i < e.target.files.length; i++) {  
            var file = e.target.files.item(i);  
            if (!(/^image\/.*$/i.test(file.type))) {  
                continue; //不是图片 就跳出这一次循环  
            }  
            //实例化FileReader  
            var freader = new FileReader();  
            freader.readAsDataURL(file);  
            freader.onload = function(e) {  
                $("#img").attr("src",e.target.result);  
            };
        }
    }
</script>
</head>
<link rel="stylesheet" href="../../css/common.css" />
		<div class="title-area bg-color-black font-normal font-white">乌托邦别墅预定管理平台>内容设置>编辑别墅</div>
	<!-- villa_detail -->
	<form action="villa_doupd" method="post" enctype="multipart/form-data">
		<div class="edit-area">
			<div class="container">
				<div class="row">
					<div class="title">编辑别墅</div>
				</div>
				<input type="hidden" name="id" value="${villa.id }"/>
				<div class="row">
					<div class="label must">别墅名称</div>
					<input type="text" class="edit" name="villaName" value="${villa.villaName }"/>
				</div>
				<div class="row">
					<div class="label must">所在店面</div>
					<select class="edit" name="storeId" >
						<option value="0">==选择店面==</option>
						<%
							//所在别墅信息
							Villa villa = (Villa)request.getAttribute("villa");
							int storeId=0;
							if(villa!=null){
								storeId = villa.getStoreId();
							}
							//店面列表
							List<Store> list_store = (List<Store>) request.getAttribute("list_store");
							if (list_store != null && list_store.size() > 0) {
								for (Store store : list_store) {
									pageContext.setAttribute("store", store);
									String selected = "";
									if (storeId == store.getId()) {
										selected = "selected";
									}
						%>
						<option value="${store.id }" <%=selected %>>${store.storename }</option>
						<%
								}
							}
						%>
					</select>
				</div>
				<div class="row">
					<div class="label must">单价</div>
					<input type="text" class="edit" name="villaPrice" value="${villa.villaPrice }"/>
				</div>
				<div class="row">
					<div class="label">上传图片</div>
					<input class="edit" type="file" name="imgPath" onChange="changeImg(event)"/>
				</div>
				<% 
					String imgPath = villa.getImgPath();
					String path = "";
					if(imgPath!=null && !"".equals(imgPath)){
						path = "upload/" + imgPath;
					}
				%>
				<div class="row">
					<img id="img" alt="" height="50%" width="50%" src="<%=path %>">
				</div>
				<div class="row">
					<div class="title">别墅描述</div>
					<textarea id="villaDescription" name="villaDescription">${villa.villaDescription }</textarea>
				</div>
				<div class="row">
				<span style="color: red;font-size: xx-small;">${errMsg}</span>
<!-- 					<button id="cancel" class="font-white button-del font-normal">取消</button> -->
					<button id="save" class="font-white button-put font-normal">保存</button>
				</div>
				
			</div>
		</div>
		</form>
		
</html>